<template>
	<el-card class="form-container">
		<el-form :model="editForm" ref="editForm" :rules="dataRule" @keyup.enter.native="dataFormSubmitHandle()" label-width="90px">
			<el-form-item label="岗位编号" prop="postCode">
				<el-input v-model="editForm.postCode" placeholder="请输入岗位编号" readonly></el-input>
			</el-form-item>
			<el-form-item label="岗位名称" prop="postName">
				<el-input v-model="editForm.postName" placeholder="请输入岗位名称" readonly></el-input>
			</el-form-item>
			<el-form-item label="岗位排序" prop="postSort">
				<el-input v-model.number="editForm.postSort" placeholder="请输入岗位排序"></el-input>
			</el-form-item>
			<el-form-item label="岗位状态" prop="postStatus">
				<el-radio-group v-model="editForm.postStatus">
					<el-radio :label="1">启用</el-radio>
					<el-radio :label="2">停用</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="岗位描述" prop="postDesc">
				<el-input v-model="editForm.postDesc" placeholder="请输入岗位描述"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button @click="cancel">取消</el-button>
				<el-button type="primary" @click="update('editForm')">确定</el-button>
			</el-form-item>
		</el-form>
	</el-card>
</template>

<script>
	import { findSystemPostDetail,editSystemPost } from '@/api/admin/systemPost'
	export default {
		name: 'user-systemPost',
		data() {
			return {
				editForm: {
					postCode: '',
					postName: '',
					postSort: '',
					postDesc: '',
					postStatus: '',
					createTime: '',
					updateTime: '',
				},
				dataRule: {
					postCode: [{
							required: true,
							message: '请输入岗位编号',
							trigger: 'blur'
						},
					],
					postName: [{
							required: true,
							message: '请输入岗位名称',
							trigger: 'blur'
						},
					],
					postSort: [{
							required: true,
							message: '请输入岗位排序',
							trigger: 'blur'
						},
					],
					postStatus: [{
							required: true,
							message: '请输入岗位状态 1.启用 2.禁用',
							trigger: 'blur'
						},
					],
				}
			}
		},
		created() {
			this.editForm.id = this.$route.query.id
			this.view(this.$route.query.id)
		},
		methods: {
			view(val) {
				findSystemPostDetail(val).then(res => {
					this.editForm = res.data.responseData
				})
			},
			cancel() {
				this.$router.go(-1)
			},
			update() {
				const set = this.$refs;
				set['editForm'].validate((valid) => {
					if (!valid) {
						return false
					}
					editSystemPost(this.editForm).then(() => {
						this.$notify({
							title: '修改成功',
							message: '修改成功',
							type: 'success',
							duration: 2000,
							onClose: this.$router.go(-1)
						})
					})
				})
			}
		}
	}
</script>

<style>
</style>
